<template>
  <div class="dashboard-editor-container">

    <div class="date-pick">
      <el-date-picker v-model="date" type="month" value-format="yyyy-MM" placeholder="选择月" @change="changeMonth">
      </el-date-picker>
    </div>
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="totalChartData" />
    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="8">
        <h4>植字</h4>
        <div class="chart-wrapper">
          <pie-chart :chart-data="userFontChartData" />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <h4>切图</h4>
        <div class="chart-wrapper">
          <pie-chart :chart-data="userCutChartData" />
        </div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
  import LineChart from './components/LineChart'
  import RaddarChart from './components/RaddarChart'
  import PieChart from './components/PieChart'
  import BarChart from './components/BarChart'
  import {
    getUsedList,
    getUsedUserList,
  } from '@/api/used'


  const chartData = {
    totalChartData:{
      cutData: [0],
      fontData: [0]
    },
    userFontChartData: {
      userData: ['user'],
      chartData: [{
        value: 0,
        name: 'user'
      }]
    },
    userCutChartData: {
      userData: ['user'],
      chartData: [{
        value: 0,
        name: 'user'
      }]
    }
  }


  export default {
    name: 'DashboardAdmin',
    components: {
      LineChart,
      RaddarChart,
      PieChart,
      BarChart,
    },
    data() {
      return {
        date: new Date(),
        year: new Date().getFullYear(),
        month: new Date().getMonth() + 1,
        totalChartData: chartData.totalChartData,
        userFontChartData: chartData.userFontChartData,
        userCutChartData: chartData.userCutChartData,
      }
    },
    created() {
      this.getList();
    },
    methods: {
      changeMonth(event) {
        var newDate = event.split("-");
        this.year = newDate[0];
        this.month = newDate[1];
        this.getList();
      },
      getList() {
        getUsedList(this.year, this.month).then(
          response => {
            this.totalChartData = response.data.totalData
            this.userFontChartData = response.data.userFontData
            this.userCutChartData = response.data.userCutData
          }).catch((error) => {
          console.log(error)
        })
      },
      handleSetLineChartData(type) {
        this.totalChartData = lineChartData[type]
      }
    }
  }
</script>

<style lang="scss" scoped>
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    h4 {
      color: #000;
    }

    .date-pick {
      margin-bottom: 15px;
    }

    .github-corner {
      position: absolute;
      top: 0px;
      border: 0;
      right: 0;
    }


  }

  @media (max-width:1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>
